import {
  getBaseCategoryList,
  reqGetBanners,
  reqGetFloors,
} from "../../api/home";
export default {
  namespaced: true,

  state: {
    categoryList: [],
    // 轮播图列表
    banners: [],
    // 楼层数据
    floors: [],
  },

  actions: {
    async getCategoryList({ commit }) {
      const res = await getBaseCategoryList();
      //   if (res.data.code == 200) {
      // 请求成功 截取前15条数据
      commit("GET_CATEGORY_LIST", res.slice(0, 15));
      //   } else {
      //     // 请求失败
      //     console.log("请求失败");
      //   }
    },
    async getBanners({ commit }) {
      try {
        const banners = await reqGetBanners();
        commit("GET_BANNERS", banners);
      } catch (e) {
        console.log(e);
      }
    },
    async getFloors({ commit }) {
      try {
        const floors = await reqGetFloors();
        commit("GET_FLOORS", floors);
      } catch (e) {
        console.log(e);
      }
    },
  },
  mutations: {
    async getCategoryList(state) {
      const data = await getBaseCategoryList();
      const result = data.data.data.slice(0, 15);
      state.categoryList = result;
    },
    async GET_CATEGORY_LIST(state, value) {
      const result = value;
      state.categoryList = result;
    },
    async GET_BANNERS(state, banners) {
      state.banners = banners;
    },
    async GET_FLOORS(state, floors) {
      state.floors = floors;
    },
  },
};
